package com.zycfc.zsf.boot.util.text;

import java.security.*;

public class MD5Utils
{
    private static char[] hexDigits;
    private static char[] hexDigits_lower;
    
    public static String MD5(final String s) throws NoSuchAlgorithmException {
        final byte[] btInput = s.getBytes();
        final MessageDigest mdInst = MessageDigest.getInstance("MD5");
        mdInst.update(btInput);
        final byte[] md = mdInst.digest();
        final int j = md.length;
        final char[] str = new char[j * 2];
        int k = 0;
        for (final byte byte0 : md) {
            str[k++] = MD5Utils.hexDigits[byte0 >>> 4 & 0xF];
            str[k++] = MD5Utils.hexDigits[byte0 & 0xF];
        }
        return new String(str);
    }
    
    public static String MD5ByLowerCase(final String s) throws NoSuchAlgorithmException {
        final byte[] btInput = s.getBytes();
        final MessageDigest mdInst = MessageDigest.getInstance("MD5");
        mdInst.update(btInput);
        final byte[] md = mdInst.digest();
        final int j = md.length;
        final char[] str = new char[j * 2];
        int k = 0;
        for (final byte byte0 : md) {
            str[k++] = MD5Utils.hexDigits_lower[byte0 >>> 4 & 0xF];
            str[k++] = MD5Utils.hexDigits_lower[byte0 & 0xF];
        }
        return new String(str);
    }
    
    static {
        MD5Utils.hexDigits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        MD5Utils.hexDigits_lower = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
    }
}
